

layui.use(['table','jquery','form'],function () {
   
   
    var $ = layui.jquery;
    var table = layui.table;
    var form=layui.form;
//    $.ajaxSettings.async=false;

	
	
  
    
    //方法渲染
    var testTable = table.render({
    	 elem: "#score1",
//       url:'../student/score?term=2017-2018&term2=2'
       autoSort: false,
       page: true,
       id: 'testReload',
      
       cols: [[
           {field: "name", title: "书名", sort: true,},
           {field: "zishu", title: "字数",},
           {field: "website", title: "网站",},
           {field: "type", title: "类型",},
           {field: "tag", title: "标签",},
       ]],
      
       
        
    
    });
    
    //查询
    $("#but").click(function(){
    		var term=$("#term").val();
    		console.log(term);	
    	if(term==null||term==""){layer.msg("请输入作者名");}
    	else{
    		$.post('../student/score',{'term':term}, function(flag) {
    			
    				console.log(flag);	
    		if(flag[0].website=="飞卢"){
    			let a=0;let b=0;let c=0;let d=0;
    			  let str="";
    	            for(let i of flag){
    	            	a+=parseInt(i.yuepiao);
    	            	b+=parseInt(i.dianji);
    	            	c+=parseInt(i.dashang);
    	            	d+=parseInt(i.xianhua);
    	               
    	            }
    	            str='月票：'+a+'<br/>'+'点击：'+b+'<br/>'+'打赏：'+c+'<br/>'+'鲜花：'+d+'<br/>';
    	            $("#hh").html(str);
   // 	            form.render();
    	            // 重新渲染 固定写法
    		 let newData = JSON.parse(JSON.stringify(flag));
        	table.reload('testReload', { 
        		       	              	      
        		 cols: [[
        			  {field: "name", title: "书名", sort: true,},
        	           {field: "zishu", title: "字数",},
        	           {field: "website", title: "网站",},
        	           {field: "type", title: "类型",},
        	           {field: "tag", title: "标签",},
        	            {field: "yuepiao", title: "月票"},
        	            {field: "dianji", title: "点击"},
        	            {field: "dashang", title: "打赏"},
        	            {field: "xianhua", title: "鲜花"},
        	           
        	        ]],
        		 data:newData, 

        		          });
    		                      }
    		else if(flag[0].website=="起点"){
    			let a=0;let b=0;let c=0;let d=0;
  			  let str="";
  	            for(let i of flag){
  	            	a+=parseInt(i.tuijian);
  	            	
  	               
  	            }
  	            str='推荐：'+a+'<br/>';
  	            $("#hh").html(str);
    			let newData = JSON.parse(JSON.stringify(flag));
            	table.reload('testReload', { 
            		       	              	      
            		 cols: [[
            			  {field: "name", title: "书名", sort: true,},
            	           {field: "zishu", title: "字数",},
            	           {field: "website", title: "网站",},
            	           {field: "type", title: "类型",},
            	           {field: "tag", title: "标签",},
            	            {field: "tuijian", title: "推荐"},
            	           
            	        ]],
            		 data:newData, 

            		          });
    		}
    		else{
    			let a=0;let b=0;let c=0;let d=0;
  			  let str="";
  	            for(let i of flag){
  	            	a+=parseInt(i.jReview);
  	            	b+=parseInt(i.jFavorite);
  	            	c+=parseInt(i.jGifts);
  	            	d+=parseInt(i.jPoint);
  	               
  	            }
  	            str='书评：'+a+'<br/>'+'收藏：'+b+'<br/>'+'营养液：'+c+'<br/>'+'总积分：'+d+'<br/>';
  	            $("#hh").html(str);
    			let newData = JSON.parse(JSON.stringify(flag));
            	table.reload('testReload', { 
            		       	              	      
            		 cols: [[
            			  {field: "name", title: "书名", sort: true,},
            	           {field: "zishu", title: "字数",},
            	           {field: "website", title: "网站",},
            	           {field: "type", title: "类型",},
            	           {field: "tag", title: "标签",},
            	            {field: "jReview", title: "书评"},
            	            {field: "jFavorite", title: "收藏"},
            	            {field: "jGifts", title: "营养液"},
            	            {field: "jPoint", title: "总积分"},
            	           
            	        ]],
            		 data:newData, 

            		          });
    		}
    		});
    	}
        
    	
				
	});
    

});




   